package com.terminee.behaviors;

import java.util.List;
import java.util.Map;

import javax.jdo.PersistenceManager;

import com.terminee.utils.PMF;


/**
 * An abstraction of DAO behaviors. Methods for basic CRUD functions to be implemented
 * by subclass and a method for custom query execution. Also includes a convenience persist
 * method.
 * 
 * @author potlow
 *
 */
public abstract class DAOBehavior {
	protected PersistenceManager pm;

    public DAOBehavior() {
        pm = PMF.getPersistenceManagerFactory().getPersistenceManager();
    }

    public abstract boolean create(Object value);
    public abstract Object read(Object value, List<String> properties);
    public abstract boolean update(Object value);
    public abstract boolean delete(Object value);
    public abstract Object excute(String filter, String declareParameters,
            Map<String, Object> parameters, List<String> properties);


    protected boolean persist(Object object) {
        boolean didPersist = false;

        try {
            pm.makePersistent(object);
            didPersist = true;
        } finally {
            pm.close();
        }

        return didPersist;
    }
}
